package 力扣日常刷题.木22一月.第10天0118;

/**
 * @author 帅小伙
 * @date 2022/1/18
 * @description
 */
public class Demo22动态规划中等丑数 {


    public int nthUglyNumber(int n) {
        int a = 0, b = 0, c = 0;
        int[] dp = new int[n];
        dp[0] = 1;
        for (int i = 1; i < n; i++) {
            int ax = dp[a] * 2, bx = dp[b] * 3, cx = dp[c] * 5;
            dp[i] = Math.min(ax, Math.min(bx, cx));
            if (dp[i] == ax) a++;
            if (dp[i] == bx) b++;
            if (dp[i] == cx) c++;
        }
        return dp[n-1];
    }

}
